package com.longlong.controller.adminApi;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.longlong.entity.RegistrationForm;
import com.longlong.entity.RegistrationPrimary;
import com.longlong.mapper.RegistrationCompetitionMapper;
import com.longlong.mapper.RegistrationFormMapper;
import com.longlong.mapper.RegistrationPrimaryMapper;
import com.longlong.vo.PaginationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 后台报名表操作
 */
@RestController
@RequestMapping("/signUp")
public class sign_up {

    @Autowired
    private RegistrationFormMapper registrationFormMapper;
    @Autowired
    private RegistrationCompetitionMapper registrationCompetitionMapper;

    /**
     * 分页查询海选报名赛事
     * @param paginationVo
     * @return
     */
    @PostMapping("/getSignUpList")
    private Object competitionSelect(@RequestBody PaginationVo paginationVo){
        Page<RegistrationForm> page = new Page<>(paginationVo.getPage(),paginationVo.getSize());
        QueryWrapper<RegistrationForm> wrapper = new QueryWrapper<>();
        wrapper.eq("competition_id",paginationVo.getCompetitionId());
        return registrationFormMapper.selectUserPage(page,wrapper);
    }


    /**
     * 获取全部赛事信息
     * @return
     */
    @PostMapping("/getAllCompetitions")
    private Object getAllCompetitions(){
        return registrationCompetitionMapper.selectList(null);
    }



    @Autowired
    private RegistrationPrimaryMapper registrationPrimaryMapper;

    @PostMapping("/confirmAudition")
    private Object confirmAudition(@RequestBody RegistrationForm registrationForm){
        registrationForm.setParticipateStatus(2);
        //给primary数据库添加进入出来的报名表
        RegistrationPrimary registrationPrimary = new RegistrationPrimary();
        registrationPrimary.setFormId(registrationForm.getId());
        registrationPrimary.setCompetitionId(registrationForm.getCompetitionId());
        registrationPrimaryMapper.insert(registrationPrimary);
        return registrationFormMapper.updateById(registrationForm);
    }

}
